<template>
	<div class="info-item">
		<div class="search-container">
			<el-form inline size="small">
				<el-form-item label="创建日期">
					<el-date-picker
						style="width: 100%"
						v-model="searchData.rangeDate"
						type="daterange"
						range-separator="~"
						start-placeholder="开始日期"
						end-placeholder="结束日期"
					></el-date-picker>
				</el-form-item>
				<el-form-item label="状态">
					<el-select v-model="searchData.status" clearable>
						<el-option
                v-for="status in statusList"
                :key="status.value"
                :label="status.label"
                :value="status.value"
              ></el-option>
					</el-select>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" @click="onSearch">查询</el-button>
					<el-button @click="onReset">重置</el-button>
				</el-form-item>
			</el-form>
		</div>
		<el-table class="el-table-modify" :data="tableData" border>
			<el-table-column type="index" align="center" width="60" label="序号"></el-table-column>
			<el-table-column prop="createdAt" align="center" label="创建时间">
				<template slot-scope="scope">
					{{scope.row.createdAt | dateFrm}}
				</template>
			</el-table-column>
			<el-table-column prop="amount" align="center" label="提现金额"></el-table-column>
			<el-table-column prop="arrivalMode" align="center" label="到账方式"></el-table-column>
			<el-table-column prop="arrivalDate" align="center" label="到账时间">
				<template slot-scope="scope">
					{{scope.row.arrivalDate | dateFrm}}
				</template>
			</el-table-column>
			<el-table-column prop="status" align="center" label="状态">
					<template slot-scope="scope">
						{{WITHDRAW_STATUS[scope.row.status]}}
					</template>
				</el-table-column>
		</el-table>
		<el-pagination
			ref="pagination"
			class="mt-20"
			background
			:page-size.sync="pageOption.pageSize"
			@size-change="onSizeChange"
			@current-change="onPageChange"
			:total="pageOption.total"
			layout="slot,->,prev,pager,next,sizes,jumper"
		>
			<span
				class="pagination-title"
			>共 {{pageOption.total}} 条记录 第 {{pageOption.page}} / {{pageOption.pageTotal}} 页</span>
		</el-pagination>
	</div>
</template>

<script>
import { withdrawRecordQuery } from "@/api/dealerMgt";
import {WITHDRAW_STATUS} from '@/utils/const';
export default {
	name: "withdrawRecord",
	props: ['id'],
	data() {
		this.statusList = Object.keys(WITHDRAW_STATUS).map(key => {
      return {
        value: key,
        label: WITHDRAW_STATUS[key]
      }
    })
		return {
			WITHDRAW_STATUS,
			searchData: {
				rangeDate: [],
				settle: ""
			},
			tableData: [],
			pageOption: {
				page: 1,
				pageSize: 20,
				total: 0,
				pageTotal: 1
			}
		};
	},
	methods: {
		onSearch() {
			this.pageOption.page = 1;
			this.requestData();
		},
		onReset() {
			this.pageOption.page = 1;
			this.searchData.rangeDate = [];
			this.searchData.settle = '';
			this.requestData();
		},
		async requestData() {
			const { page, pageSize: size } = this.pageOption;
			const postData = {};
			Object.keys(this.searchData).forEach(key => {
				if (this.searchData[key]) {
					postData[key] = this.searchData[key];
				}
			});

			const { data, total } = await withdrawRecordQuery(this.id, {
				page: page - 1,
				size,
				...postData
			});
			this.tableData = data;
			this.pageOption.total = total || 0;
			this.pageOption.pageTotal = total ? Math.ceil(total / size) : 1;

			if (this.$refs.pagination) {
				let childrenRefs = this.$refs.pagination.$children;
				this.$nextTick(() => {
					childrenRefs.forEach(child => child.$forceUpdate());
				});
			}
		},
		onSizeChange(size) {
			this.pageOption.pageSize = size;
			this.requestData();
		},
		onPageChange(page) {
			this.pageOption.page = page;
			this.requestData();
		}
	},
	created() {
		this.requestData()
	}
};
</script>

<style scoped lang="scss">
</style>
